package ctrl.svr;

import java.net.*;
import java.io.*;

public class SimpleClient {
	private int sPORT=3030;
	private String ipAddr;
	//public String endflag="/r/n";
	public Socket s;
	public DataOutputStream dout;
	public boolean conn;
	public SimpleClient(String ip,int sport)
	{
		this.sPORT=sport;
		this.ipAddr=ip;
		
	}
	public boolean SetUp()
	{
		try{
		s=new Socket(ipAddr,sPORT);
		if(s.isConnected())
		{
			//System.out.println(s.getInetAddress().toString());
			conn=true;
			return true;
		}
		}catch(Exception e)
		{
			return false;
			//System.out.println(e.getStackTrace()+"/setup");
		}
		return false;
	}
	
	public boolean SendCom(String str)
	{
		if(s.isConnected())
		{
			try{
			dout=new DataOutputStream(s.getOutputStream());
			dout.writeUTF(str);
			return true;
			//dout.writeUTF(endflag);		
			}catch(Exception e)
			{
				return false;
				//System.out.println(e.getStackTrace()+"/sendcom");
			}
		}
		return false;
	}
	public boolean SClose()
	{
		try{

		s.close();
		return true;
		}catch(Exception e)
		{
			System.out.println("something wrong here in closing");			
		}
		
		return false;
		
	}

}
